package com.wy2cloud.gateway.controller.auth;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wy2cloud.core.web.CookieTools;
import com.wy2cloud.gateway.feignclients.UserClient;
import com.wy2cloud.jjwt.JsonWebTokenUtil;

@RequestMapping("/auth")
@RestController
public class AuthController {

	@Autowired
	private JsonWebTokenUtil jsonWebTokenUtil;
	
	@RequestMapping("/token")
	public String index(HttpServletResponse response) {
		Map<String,Object> moreInfo=new HashMap<>();
		moreInfo.put("userId", "00000000000000000000000000000000");
		moreInfo.put("age", "22");
		moreInfo.put("sex", "男");
		String token= jsonWebTokenUtil.generateToken("admin",0L,moreInfo);
		
		CookieTools.addCookie(response,jsonWebTokenUtil.getTokenHeader(), jsonWebTokenUtil.getTokenHead()+ token, 3600);
		
		return token;
	}
}
